<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://unpkg.com/vue@3"></script>
  </head>
  <body>
    <div id="app">
      <!-- 添加用户区域 -->
      <div>
        <input  type="text" v-model="name">
        <button @click="addNewUser">添加</button>
      </div>
      <!-- 用户列表展示区 -->
      <div>
        <ul>
          <li v-for="(user,i) in userList" :key="user.id">
            <input type="checkbox" >
            id：{{user.id}}
            姓名:{{user.name}}
          </li>
        </ul>
      </div>
    </div>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            userList: [
              { id: 1, name: "zs" },
              { id: 2, name: "ls" },
              { id: 3, name: "ww" },
            ],
            name:'',
            id:4,
          };
        },
        methods:{
          addNewUser(){
            if(this.name != ''){
              this.userList.unshift({id:this.id,name:this.name})
              this.id ++
            }else{
              window.alert("姓名为空无法添加！")
            }
          }
        },
      }).mount("#app");
    </script>
  </body>
</html>
